package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;


public class Not extends UnaryExpression{
	public Not(E expression){
		super(expression);			
	}

	private boolean isValidExpression(E e){
		return e.isBoolean() || e.isString();
	}

	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		try{
			if(getExpression().getContent(map, givenCollisionObject) instanceof Boolean){
				if(isValidExpression(getExpression())){
					return !((boolean) getExpression().getContent(map, givenCollisionObject));
				}
			}
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
		catch (NullPointerException exc) {
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
	}

	public boolean isBoolean(){
		return true;
	}
	public boolean isDouble() {
		return false;
	}
	public boolean isEntity(){
		return false;
	}
	public boolean isString(){
		return false;
	}
}
